﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using HighDivePrinter.View;
using HighDivePrinter.Properties;
using HighDivePrinter.Presenter;
using HighDivePrinter.Model;


namespace HighDivePrinter
{
    public partial class FormJudge : Form , IFormJudge
    {
        private int _row = -1;
        public FormJudge()
        {
            InitializeComponent();
        }

        private void _buttonNewJudge_Click(object sender, EventArgs e)
        {
            if (this.EventAddJudgeList != null)
                this.EventAddJudgeList();
        }

        private void _buttonSaveJudge_Click(object sender, EventArgs e)
        {
            if (this.EventSaveJudgeList != null)
                this.EventSaveJudgeList();
        }

        private void _buttonReadJudges_Click(object sender, EventArgs e)
        {
            if (this.EventReadJudgeList != null)
                this.EventReadJudgeList();
        }

        private void _buttonDeleteJudge_Click(object sender, EventArgs e)
        {
            //this._row = this._dataGridView.Rows.
            if (this._row != -1)
                if (this.EventRemoveJudgeList != null)
                    this.EventRemoveJudgeList(this._row);
            this._row = 1;

        }

        #region IFormJudge Members

        //Judge Class members
        void IFormJudge.SetJudgeList(BindingList<Judge> judge)
        {
            this._dataGridView.DataSource = judge;
        }

        public event DelegateAddJudgeList EventAddJudgeList = null;
        public event DelegateRemoveJudgeList EventRemoveJudgeList = null;
        public event DelegateSaveJudgeList EventSaveJudgeList = null;
        public event DelegateReadJudgeList EventReadJudgeList = null;

        #endregion

        private void _dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //judge
            this._row = e.RowIndex;
        }

        #region Printing

        /// <summary>
        /// Händelsemetod för att hantera EVENT ButtonClick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        private void _buttonPrint_Click(object sender, EventArgs e)
        {
            PrintDocumentJudge jl = new PrintDocumentJudge((BindingList<Judge>)this._dataGridView.DataSource);
            jl.MyPrint();
        }
        #endregion


    }
}
